--
-- Author: shunguo.chen
-- Date: 2018-06-01 14:15:20
--
-- QuickUseView 	快捷装备／使用界面
--

local IconSimpleRender = require("app.widget.renders.IconSimpleRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.QuickUseScene

function ClassRef:init()
	self._iconRender = IconSimpleRender.create(self._ui.Icon)

	self._ui.Button_back:addClickEventListener(function()
			executeFunc(self._onOperate, "close")
		end)
	self._ui.Button:addClickEventListener(function()
			if self._data then
				executeFunc(self._onOperate, "useItem", self._data)
			end
		end)

	self._btnNameText = self._ui.Button:getChildByName("Text_5")
end

function ClassRef:show(ignoreDispatch)
	self.super.show(self)

	local timeline = self._root:getTimeline()
	timeline:setLastFrameCallFunc(function()
			-- guide
			self:checkGuide()
		end)

    if not ignoreDispatch then
        executeFunc(self._onOperate, "visibleChange", true)
    end
end

function ClassRef:hide(isKeepData, ignoreDispatch)
    if not isKeepData then
       self._data = nil
    end
    self.super.hide(self)

    if not ignoreDispatch then
        executeFunc(self._onOperate, "visibleChange", false)
    end
end

-- 检查是否触发了引导(装备才需要引导)
function ClassRef:checkGuide()
    if not self:isVisible() then return end
	if self._data == nil then return end
	if UIHandler:isHaveUI() then return end
	if self._data.itemBagType ~= Enums.ItemBagType.equip then return end

    local params = {
        scene = Constant.FUNC_TYPE_QUICK_USE,
        sceneSelf = self,
        getFunc = self.getGuideNodeFunc,
        nextFunc = self.checkGuide
    }
    EM:notify("checkGuide", params)
end

-- 获取引导node
function ClassRef:getGuideNodeFunc(id)
    return self._ui.Button
end

function ClassRef:refresh(data)
	self._data = data
	self._iconRender:setData(data)
	self._ui.name:setString(data:getName())

	if data.itemBagType == Enums.ItemBagType.equip then
		self._btnNameText:setString(L("tips_1000037"))
	else
		self._btnNameText:setString(L("tips_1000017"))
	end
end

return ClassRef
